package com.jd.jr.insights.dm.dim.controller;

import com.jd.jr.insights.dm.dim.domain.Business;
import com.jd.jr.insights.dm.dim.service.BizService;
import com.jd.jr.insights.dm.dim.service.impl.BizServiceImpl;
import com.jd.jr.insights.dm.dim.util.LOG;
import com.jfinal.core.Controller;

import java.util.Enumeration;

/**
 * Created by Administrator on 2017/7/15.
 */
public class BizController extends Controller {
    BizService bizService=new BizServiceImpl();
    public void index() {
        render("/biz.html");
    }

    public void getAllTreeEnumList() {
        int biz_id = getParaToInt("dimId");
        LOG.INFO("dimId", biz_id + "");
        renderText("");
    }


    public void getAllBizList() {
        LOG.INFO("getAllBizList()",bizService.getBizListJson());
        renderText(bizService.getBizListJson());
    }

    public void getAllBizListNm() {
        LOG.INFO("getAllBizList()",bizService.getBizListJson());
        renderText(bizService.getBizListJsonNm());
    }



    public void save() {

        Integer parent_id=getParaToInt("parent_id");
        String code=getPara("code");
        String desc=getPara("desc");
        String name=getPara("value");
        Integer level=getParaToInt("level");

        Business biz=new Business();

        biz.setCode(code);
        biz.setValue(name);
        biz.setParent_id(parent_id);
        biz.setDesc(desc);
        biz.setLevel(level);
        renderText(bizService.save(biz));
    }

    public void update() {
        Enumeration e = getAttrNames();
        while (e.hasMoreElements()) {
            Object o = e.nextElement();
            LOG.INFO("update()",o.toString());
        }
        Integer biz_id=getParaToInt("id");
        String code=getPara("code");
        String name=getPara("value");
        String desc=getPara("desc");


        Business biz=new Business();
        biz.setBiz_id(biz_id);
        biz.setCode(code);
        biz.setValue(name);
        biz.setDesc(desc);
        renderText(bizService.update(biz));

    }

    public void deleteById(){
        Integer biz_id=getParaToInt("id");
        Business biz=new Business();
        biz.setBiz_id(biz_id);
        renderText(bizService.deleteById(biz));
    }


    public void getByDimDefId(){
        Enumeration e = getAttrNames();
        while (e.hasMoreElements()) {
            Object o = e.nextElement();
            LOG.INFO("deleteById()",o.toString());
        }
        renderText("");
    }

    public void generateLvlTableData(){

    }

    public void saveTreeToLvl(){

    }
}
